package tp.pr3.items;

import tp.pr3.NavigationModule;
import tp.pr3.Place;
import tp.pr3.RobotEngine;

/**
 * An item that represents fuel. This item can be used at least once and it
 * provides power energy to the robot. When the item is used the configured
 * number of times, then it must be removed from the robot inventory
 */
public class Fuel extends Item {

	private int power;
	private int times;

	/**
	 * Fuel constructor
	 * 
	 * @param id
	 *            - Item id
	 * @param description
	 *            - Item description
	 * @param power
	 *            - The amount of power energy that this item provides the robot
	 * @param times
	 *            - Number of times the robot can use the item
	 */
	public Fuel(java.lang.String id, java.lang.String description, int power,
			int times) {
		super(id, description);
		this.power = power;
		this.times = times;
	}

	@Override
	/**
	 * Fuel can be used as many times as it was configured
	 * return - iff the item can still be used
	 */
	public boolean canBeUsed() {
		return (times > 0);
	}

	@Override
	/**
	 * Using the fuel provides energy to the robot (if it can be used)
	 * return true if the fuel has been used
	 */
	public boolean use(RobotEngine r, NavigationModule n) {
		if (canBeUsed()) {
			r.addFuel(power);
			System.out.println(r.statusInfo());
			times--;
			return true;
		} else
			return false;
	}

	@Override
	public java.lang.String toString() {
		return id + ": " + description + "// power = " + power + ", times = " + times;
	}

}
